<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <title>二分查找 - 欢迎来到SY的博客</title><meta name="description" content="二分查找"><meta property="og:title" content="二分查找" />
<meta property="og:description" content="二分查找" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://acking-you.gitee.io/posts/%C3%A4%C2%BA%C3%A5%C3%A6%C3%A6/" /><meta property="og:image" content="https://acking-you.gitee.io/logo.png"/><meta property="article:section" content="posts" />
<meta property="article:published_time" content="2022-08-15T00:00:00+00:00" />
<meta property="article:modified_time" content="2022-08-15T00:00:00+00:00" />

<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://acking-you.gitee.io/logo.png"/>

<meta name="twitter:title" content="二分查找"/>
<meta name="twitter:description" content="二分查找"/>
<meta name="application-name" content="FeelIt">
<meta name="apple-mobile-web-app-title" content="FeelIt"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="canonical" href="https://acking-you.gitee.io/posts/%C3%A4%C2%BA%C3%A5%C3%A6%C3%A6/" /><link rel="prev" href="https://acking-you.gitee.io/posts/%C3%A7%C3%A9%C3%A5-%C3%A7-/" /><link rel="next" href="https://acking-you.gitee.io/posts/%C3%A9%C3%A5%C2%BA%C3%A6%C3%A5%C3%A7%C3%A5%C3%A6%C3%A7/" /><link rel="stylesheet" href="/css/page.min.css"><link rel="stylesheet" href="/css/home.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "二分查找",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/acking-you.gitee.io\/posts\/%C3%A4%C2%BA%C3%A5%C3%A6%C3%A6\/"
        },"genre": "posts","keywords": "二分查找","wordcount":  1766 ,
        "url": "https:\/\/acking-you.gitee.io\/posts\/%C3%A4%C2%BA%C3%A5%C3%A6%C3%A6\/","datePublished": "2022-08-15T00:00:00+00:00","dateModified": "2022-08-15T00:00:00+00:00","publisher": {
            "@type": "Organization",
            "name": "作者"},"author": {
                "@type": "Person",
                "name": "作者"
            },"description": "二分查找"
    }
    </script></head><body data-header-desktop="auto" data-header-mobile="auto"><script>(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('auto' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'auto' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="欢迎来到SY的博客">欢迎来到SY的博客</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="#" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="欢迎来到SY的博客">欢迎来到SY的博客</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="#" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="#" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><div class="menu-item"><a href="javascript:void(0);" class="theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div></div>
    </div>
</header><div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div><main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single" data-toc="disable"><div class="featured-image"><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/img_convert/c644e86b92d93fcc4173c23ce127e625.png#pic_center"
        data-srcset="https://img-blog.csdnimg.cn/img_convert/c644e86b92d93fcc4173c23ce127e625.png#pic_center, https://img-blog.csdnimg.cn/img_convert/c644e86b92d93fcc4173c23ce127e625.png#pic_center 1.5x, https://img-blog.csdnimg.cn/img_convert/c644e86b92d93fcc4173c23ce127e625.png#pic_center 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/img_convert/c644e86b92d93fcc4173c23ce127e625.png#pic_center"
        title="二分查找" /></div><div class="single-card" data-image="true"><h2 class="single-title animated flipInX">二分查找</h2><div class="post-meta">
                <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel=" author" class="author"><i class="fas fa-user-circle fa-fw"></i>作者</a></span>&nbsp;<span class="post-category">出版于  <a href="/categories/%E7%AE%97%E6%B3%95%E7%9A%84%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/"><i class="far fa-folder fa-fw"></i>算法的深度学习</a></span></div>
                <div class="post-meta-line"><span><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2022-08-15">2022-08-15</time></span>&nbsp;<span><i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 1766 字</span>&nbsp;
                    <span><i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 4 分钟</span>&nbsp;</div>
            </div>
            
            <hr><div class="details toc" id="toc-static"  data-kept="">
                    <div class="details-summary toc-title">
                        <span>目录</span>
                        <span><i class="details-icon fas fa-angle-right"></i></span>
                    </div>
                    <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li><a href="#二分查找">二分查找</a></li>
    <li><a href="#思路">思路</a></li>
    <li><a href="#左闭右闭">左闭右闭</a></li>
    <li><a href="#左闭右开">左闭右开</a></li>
    <li><a href="#总结">总结</a></li>
  </ul>
</nav></div>
                </div><div class="content" id="content"><h2 id="二分查找">二分查找</h2>
<p><a href="https://leetcode.cn/problems/binary-search/" target="_blank" rel="noopener noreffer">力扣题目链接</a></p>
<p>给定一个n个元素有序的(升序)整数型数组nums和一个目标值target，写一个函数搜素nums中的target，如果目标值存在返回下标，否则返回-1。</p>
<p>示例1：</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151055458.png"
        data-srcset="https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151055458.png, https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151055458.png 1.5x, https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151055458.png 2x"
        data-sizes="auto"
        alt="https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151055458.png"
        title="image-20220815105541384" /></p>
<p>示例2：</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151057589.png"
        data-srcset="https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151057589.png, https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151057589.png 1.5x, https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151057589.png 2x"
        data-sizes="auto"
        alt="https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151057589.png"
        title="image-20220815105722561" /></p>
<p>提示：</p>
<ul>
<li>
<p>你可以假设nums中所有元素是不重复的。</p>
</li>
<li>
<p>n将在[1,1000]之间。</p>
</li>
<li>
<p>nums的每个元素都将在[-9999,9999]之间。</p>
</li>
</ul>
<h2 id="思路">思路</h2>
<p><strong>这道题目的前提是数组为有序数组</strong>，同时题目还强调<strong>数组中无重复元素</strong>，因为一旦有重复元素，使用二分查找法返回的元素下标可能不是唯一的，这些都是使用二分法的前提条件，当看到这些条件时，就可以想到这是要用到二分法解题。</p>
<p>二分查找涉及的很多边界条件，逻辑比较简单，但是很容易出错，例如while(left&lt;right)还是while(left&lt;=right)，到底是right=middle呢，还是right=middle-1呢?</p>
<p>我们经常把二分法写乱，主要是因为对区间的定义没有想清楚，区间的定义就是不变量。要在二分法查找中，保持不变量，就是在while中寻找每一次边界的处理都要坚持根据区间的定义来操作，这就是循环不变量的规制。</p>
<p>写二分法，区间定义一般分为两种，左闭有闭即[left,right]，或者左闭右开即[left,right)。</p>
<p>下面我会用这两种区间的定义分别讲解两种不同的二分写法。</p>
<h2 id="左闭右闭">左闭右闭</h2>
<p>第一种写法为左闭右闭，我们定义的target在一个左闭右闭的区间中，<strong>也就是[left,right]</strong>。</p>
<ul>
<li>
<p>while(left&lt;=right)要使用&lt;=，因为left==right有意义，所以使用&lt;=。</p>
</li>
<li>
<p>if(target&lt;nums[middle])right要赋值为middle-1，因为当前这个nums[middle]一定不是target，那么接下来要查找的做区间结束下标位置就是middle-1。</p>
</li>
</ul>
<p>例如在数组：1,2,3,4,7,9,10中查找元素2，如下所示：</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151115248.png"
        data-srcset="https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151115248.png, https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151115248.png 1.5x, https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151115248.png 2x"
        data-sizes="auto"
        alt="https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151115248.png"
        title="image-20220815111532187" /></p>
<p>代码如下：(注释十分详细)</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-CPP" data-lang="CPP"><span class="cm">/*版本1-左闭右闭*/</span>
<span class="k">class</span> <span class="nc">Solution</span> <span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
    <span class="kt">int</span> <span class="n">search</span><span class="p">(</span><span class="n">vector</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;&amp;</span> <span class="n">nums</span><span class="p">,</span> <span class="kt">int</span> <span class="n">target</span><span class="p">)</span> <span class="p">{</span>
        <span class="c1">//区间中的最小值的下标
</span><span class="c1"></span>        <span class="kt">int</span> <span class="n">left</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
        <span class="c1">//区间中最大值的下标
</span><span class="c1"></span>        <span class="kt">int</span> <span class="n">right</span><span class="o">=</span><span class="n">nums</span><span class="p">.</span><span class="n">size</span><span class="p">()</span><span class="o">-</span><span class="mi">1</span><span class="p">;</span>
        <span class="c1">//根据题意为左闭右闭，所以left可以等于right
</span><span class="c1"></span>        <span class="k">while</span><span class="p">(</span><span class="n">left</span><span class="o">&lt;=</span><span class="n">right</span><span class="p">)</span>
        <span class="p">{</span>
            <span class="c1">//这里加left是防止下标溢出，等同于(left+right)/2
</span><span class="c1"></span>            <span class="kt">int</span> <span class="n">middle</span><span class="o">=</span><span class="p">(</span><span class="n">left</span><span class="o">+</span><span class="n">right</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="o">+</span><span class="n">left</span><span class="p">;</span>
            <span class="c1">//当目标值小于中间值时
</span><span class="c1"></span>            <span class="k">if</span><span class="p">(</span><span class="n">target</span><span class="o">&lt;</span><span class="n">nums</span><span class="p">[</span><span class="n">middle</span><span class="p">])</span>
            <span class="p">{</span>
                <span class="c1">//目标值在左边，所以[left,middle-1]
</span><span class="c1"></span>                <span class="n">right</span><span class="o">=</span><span class="n">middle</span><span class="o">-</span><span class="mi">1</span><span class="p">;</span>
            <span class="p">}</span>
            <span class="c1">//当目标值大于中间值
</span><span class="c1"></span>            <span class="k">else</span> <span class="nf">if</span><span class="p">(</span><span class="n">target</span><span class="o">&gt;</span><span class="n">nums</span><span class="p">[</span><span class="n">middle</span><span class="p">])</span>
            <span class="p">{</span>
                <span class="c1">//target在右边，[middle+1,right]
</span><span class="c1"></span>                <span class="n">left</span><span class="o">=</span><span class="n">middle</span><span class="o">+</span><span class="mi">1</span><span class="p">;</span>
            <span class="p">}</span>
            <span class="c1">//目标值等于中间值
</span><span class="c1"></span>            <span class="k">else</span><span class="p">{</span>
                <span class="c1">//返回中间值的下标
</span><span class="c1"></span>                <span class="k">return</span> <span class="n">middle</span><span class="p">;</span>
            <span class="p">}</span>
        <span class="p">}</span>
        <span class="c1">//未找到
</span><span class="c1"></span>        <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">};</span>
</code></pre></div><h2 id="左闭右开">左闭右开</h2>
<p>如果target在一个左闭右开的区间中，也就是[left,right)，那么二分法的边界处理方法截然不同。</p>
<p>有如下两点：</p>
<ul>
<li>
<p>while(left&lt;right)，在这里使用&lt;，因为left==right在区间[left,right)没有意义。</p>
</li>
<li>
<p>if(nums[middle]&gt;target)right更新为middle，因为当前的nums[middle]不等于target，去左边区间继续寻找，而区间是左闭右开的，所以right更新为middle，即下一个查找区间不会去比较nums[middle]。</p>
</li>
</ul>
<p>在数组：1,2,3,4,7,9，10中查找元素2，如下图所示：</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151130849.png"
        data-srcset="https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151130849.png, https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151130849.png 1.5x, https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151130849.png 2x"
        data-sizes="auto"
        alt="https://raw.githubusercontent.com/jjking20010901/typora/master/img202208151130849.png"
        title="image-20220815113045794" /></p>
<p>代码如下所示：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-CPP" data-lang="CPP"><span class="cm">/*版本2-左闭右开*/</span>
<span class="k">class</span> <span class="nc">Solution</span> <span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
    <span class="kt">int</span> <span class="n">search</span><span class="p">(</span><span class="n">vector</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;&amp;</span> <span class="n">nums</span><span class="p">,</span> <span class="kt">int</span> <span class="n">target</span><span class="p">)</span> <span class="p">{</span>
        <span class="c1">//区间中的最小值的下标
</span><span class="c1"></span>        <span class="kt">int</span> <span class="n">left</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
        <span class="c1">//区间中最大值的下标
</span><span class="c1"></span>        <span class="kt">int</span> <span class="n">right</span><span class="o">=</span><span class="n">nums</span><span class="p">.</span><span class="n">size</span><span class="p">()</span><span class="o">-</span><span class="mi">1</span><span class="p">;</span>
        <span class="c1">//根据题意为左闭右开，所以left不等于right
</span><span class="c1"></span>        <span class="k">while</span><span class="p">(</span><span class="n">left</span><span class="o">&lt;</span><span class="n">right</span><span class="p">)</span>
        <span class="p">{</span>
            <span class="c1">//这里加left是防止下标溢出，等同于(left+right)/2
</span><span class="c1"></span>            <span class="kt">int</span> <span class="n">middle</span><span class="o">=</span><span class="p">(</span><span class="n">left</span><span class="o">+</span><span class="n">right</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="o">+</span><span class="n">left</span><span class="p">;</span>
            <span class="c1">//当目标值小于中间值时
</span><span class="c1"></span>            <span class="k">if</span><span class="p">(</span><span class="n">target</span><span class="o">&lt;</span><span class="n">nums</span><span class="p">[</span><span class="n">middle</span><span class="p">])</span>
            <span class="p">{</span>
                <span class="c1">//目标值在左边，所以[left,middle)
</span><span class="c1"></span>                <span class="n">right</span><span class="o">=</span><span class="n">middle</span><span class="p">;</span>
            <span class="p">}</span>
            <span class="c1">//当目标值大于中间值
</span><span class="c1"></span>            <span class="k">else</span> <span class="nf">if</span><span class="p">(</span><span class="n">target</span><span class="o">&gt;</span><span class="n">nums</span><span class="p">[</span><span class="n">middle</span><span class="p">])</span>
            <span class="p">{</span>
                <span class="c1">//target在右边，[middle+1,right)
</span><span class="c1"></span>                <span class="n">left</span><span class="o">=</span><span class="n">middle</span><span class="o">+</span><span class="mi">1</span><span class="p">;</span>
            <span class="p">}</span>
            <span class="c1">//目标值等于中间值
</span><span class="c1"></span>            <span class="k">else</span><span class="p">{</span>
                <span class="c1">//返回中间值的下标
</span><span class="c1"></span>                <span class="k">return</span> <span class="n">middle</span><span class="p">;</span>
            <span class="p">}</span>
        <span class="p">}</span>
        <span class="c1">//未找到
</span><span class="c1"></span>        <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">};</span>
</code></pre></div><h2 id="总结">总结</h2>
<p>二分法是非常重要的基础算法，但很多人总是写错。</p>
<p>其实主要原因就是对区间的定义没有理解清楚，在循环中没有始终坚持根据查找区间的定义来做边界处理。</p>
<p>区间的定义就是不变量，那么在循环中坚持根据区间的定义来做边界处理，就是循环不变量规则。</p>
<p>本篇文章根据两种常见的区间定义，给出两种二分法的写法，每一个边界为什么这么处理，都根据区间的定义做了详细介绍。</p>
<p>相信看完本篇文章应该对二分法有了更深的理解。</p>
</div><div class="post-footer" id="post-footer">
    <div class="post-info"><div class="post-info-tag"><span><a href="/tags/%E4%BA%8C%E5%88%86%E6%9F%A5%E6%89%BE/">二分查找</a>
                </span></div><div class="post-info-line"><div class="post-info-mod">
                <span>更新于 2022-08-15</span>
            </div><div class="post-info-mod"></div>
        </div><div class="post-info-share">
            <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="https://acking-you.gitee.io/posts/%C3%A4%C2%BA%C3%A5%C3%A6%C3%A6/" data-title="二分查找" data-hashtags="二分查找"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="https://acking-you.gitee.io/posts/%C3%A4%C2%BA%C3%A5%C3%A6%C3%A6/" data-hashtag="二分查找"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 WhatsApp" data-sharer="whatsapp" data-url="https://acking-you.gitee.io/posts/%C3%A4%C2%BA%C3%A5%C3%A6%C3%A6/" data-title="二分查找" data-web><i class="fab fa-whatsapp fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="https://acking-you.gitee.io/posts/%C3%A4%C2%BA%C3%A5%C3%A6%C3%A6/" data-title="二分查找"><i class="fab fa-line fa-fw"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="https://acking-you.gitee.io/posts/%C3%A4%C2%BA%C3%A5%C3%A6%C3%A6/" data-title="二分查找" data-image="https://img-blog.csdnimg.cn/img_convert/c644e86b92d93fcc4173c23ce127e625.png#pic_center"><i class="fab fa-weibo fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Myspace" data-sharer="myspace" data-url="https://acking-you.gitee.io/posts/%C3%A4%C2%BA%C3%A5%C3%A6%C3%A6/" data-title="二分查找" data-description="二分查找"><i data-svg-src="/lib/simple-icons/icons/myspace.min.svg"></i></a><a href="javascript:void(0);" title="分享到 Blogger" data-sharer="blogger" data-url="https://acking-you.gitee.io/posts/%C3%A4%C2%BA%C3%A5%C3%A6%C3%A6/" data-title="二分查找" data-description="二分查找"><i class="fab fa-blogger fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Evernote" data-sharer="evernote" data-url="https://acking-you.gitee.io/posts/%C3%A4%C2%BA%C3%A5%C3%A6%C3%A6/" data-title="二分查找"><i class="fab fa-evernote fa-fw"></i></a></span>
        </div></div><div class="post-nav"><a href="/posts/%C3%A7%C3%A9%C3%A5-%C3%A7-/" class="prev" rel="prev" title="移除元素"><i class="fas fa-angle-left fa-fw"></i>Previous Post</a>
            <a href="/posts/%C3%A9%C3%A5%C2%BA%C3%A6%C3%A5%C3%A7%C3%A5%C3%A6%C3%A7/" class="next" rel="next" title="长度最小的子数组">Next Post<i class="fas fa-angle-right fa-fw"></i></a></div></div>
</div></article></div>
            </main>
            <footer class="footer"><div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.86.0">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/khusika/FeelIt" target="_blank" rel="noopener noreffer" title="FeelIt 1.0.1"><i class="fas fa-hand-holding-heart fa-fw"></i> FeelIt</a>
        </div><div class="footer-line" itemscope itemtype="http://schema.org/CreativeWork"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2022</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/"></a></span></div>
</div>
</footer>
        </div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-chevron-up fa-fw"></i>
            </a></div><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><link rel="stylesheet" href="/lib/katex/katex.min.css"><link rel="stylesheet" href="/lib/katex/copy-tex.min.css"><script src="/lib/autocomplete/autocomplete.min.js"></script><script src="/lib/lunr/lunr.min.js"></script><script src="/lib/lunr/lunr.stemmer.support.min.js"></script><script src="/lib/lunr/lunr.zh.min.js"></script><script src="/lib/lazysizes/lazysizes.min.js"></script><script src="/lib/clipboard/clipboard.min.js"></script><script src="/lib/sharer/sharer.min.js"></script><script src="/lib/katex/katex.min.js"></script><script src="/lib/katex/auto-render.min.js"></script><script src="/lib/katex/copy-tex.min.js"></script><script src="/lib/katex/mhchem.min.js"></script><script>window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":200},"comment":{},"math":{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":true,"left":"\\[","right":"\\]"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"}],"strict":false},"search":{"highlightTag":"em","lunrIndexURL":"/index.json","lunrLanguageCode":"zh","lunrSegmentitURL":"/lib/lunr/lunr.segmentit.js","maxResultLength":100,"noResultsFound":"没有找到结果","snippetLength":50,"type":"lunr"}};</script><script src="/js/theme.min.js"></script></body></html>
